//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	IQueryBuilder.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Entities
{
	/// <summary>
	/// Query Builder
	/// </summary>
	public interface IQueryBuilder
	{
		/// <summary>
		/// Fields Metadata
		/// </summary>
		MetaFields Meta { get; set; }

		/// <summary>
		/// Format Query (Where, OrderBy, GroupBy)
		/// </summary>
		string FormatQuery();

		/// <summary>
		/// Return Query properties
		/// </summary>
		Dictionary<string, object> GetProperties();
	}

	/// <summary>
	/// Query Builder
	/// </summary>
	public interface IQueryBuilder<TExecutorType> : IQueryBuilder
		where TExecutorType : class
	{
		/// <summary>
		/// Where part of QueryBuilder query
		/// </summary>
		IQueryBuilderWhere<TExecutorType> Where { get; }

		/// <summary>
		/// OrderBy part of QueryBuilder query
		/// </summary>
		IQueryBuilderOrderBy<TExecutorType> OrderBy { get; }

		/// <summary>
		/// GroupBy part of QueryBuilder query
		/// </summary>
		IQueryBuilderGroupBy<TExecutorType> GroupBy { get; }

		/// <summary>
		/// Filter field using op
		/// </summary>
		IQueryBuilder<TExecutorType> Filter(string field, FilterCondition op);

		/// <summary>
		/// Filter field using op and value
		/// </summary>
		IQueryBuilder<TExecutorType> Filter(string field, FilterCondition op, object value);

		/// <summary>
		/// Sort by field
		/// </summary>
		IQueryBuilder<TExecutorType> Sort(string field, bool asc);

		/// <summary>
		/// Group by field
		/// </summary>
		IQueryBuilder<TExecutorType> Group(string field);

		/// <summary>
		/// Query executor
		/// </summary>
		TExecutorType Executor { get; }

		/// <summary>
		/// Return casted query executor
		/// </summary>
		TMyExecutorType GetExecutor<TMyExecutorType>()
			where TMyExecutorType : TExecutorType;
	}
}